layui.use(['Api', 'echarts', 'request', 'layer'], function () {
    let echarts = layui.echarts;
    var Api = layui.Api,
        request = layui.request,
        layer = layui.layer;

    var column1 = echarts.init(document.getElementById('column1'));

    var option = {
        title: {
            text: '移送单位全部案件统计',
            // subtext: '各个单位',
            left: 'center'
        },
        tooltip: {
            trigger: 'axis',
            axisPointer: {
                type: 'shadow',
                textStyle: {
                    color: '#fff',
                    fontSize: '26'
                },
            }
        },
        legend: {
            top: '5%',
            right: '10%',
            data: ['移送案件', '查结案件'],
            textStyle: {
                fontSize: 14,
                color: '#808080'
            },
            icon: 'rect'
        },
        grid: {
            top: 60,
            left: 50,
            bottom: 60,
            right: 60
        },
        xAxis: [{
            type: 'category',
            axisTick: {
                show: false
            },
            axisLine: {
                show: false
            },
            axisLabel: {
                color: '#4D4D4D',
                fontSize: 13,
                margin: 16,
                fontWeight: 'bold'
            },
            data: ['市公安局', '市检察院', '市中级法院', '市司法局', '海事法院', '其它外单位'],
        }],
        yAxis: [{
            name: '单位：件',
            nameTextStyle: {
                color: '#808080',
                fontSize: 12,
                padding: [0, 0, 0, -5]
            },
            max: function (value) {
                if (value.max < 5) {
                    return 5
                } else {
                    return value.max
                }
            },
            type: 'value',
            axisLine: {
                show: false
            },
            axisLabel: {
                color: '#808080',
                fontSize: 14,
                margin: 5
            },
            splitLine: {
                show: false
            },
            axisTick: {
                show: false
            }
        }],
        series: [
            {
                name: '移送案件',
                type: 'bar',
                label: {
                    show: true,
                    position: 'top',
                    fontSize: 18,
                    color: '#3DC3F9',
                    fontWeight: 'bold'
                },
                barMaxWidth: 60,
                itemStyle: {
                    color: {
                        type: 'linear',
                        x: 0,
                        y: 0,
                        x2: 0,
                        y2: 1,
                        colorStops: [{
                            offset: 0, color: '#3D8BF0' // 0% 处的颜色
                        }, {
                            offset: 1, color: '#CCE2FF' // 100% 处的颜色
                        }]
                    }
                },
                data: [65, 120, 155, 120, 140, 110]
            },
            {
                name: '查结案件',
                type: 'bar',
                label: {
                    show: true,
                    position: 'top',
                    fontSize: 18,
                    color: '#A9DF96',
                    fontWeight: 'bold'
                },
                barMaxWidth: 60,
                itemStyle: {
                    color: {
                        type: 'linear',
                        x: 0,
                        y: 0,
                        x2: 0,
                        y2: 1,
                        colorStops: [{
                            offset: 0, color: '#91CC75' // 0% 处的颜色
                        }, {
                            offset: 1, color: '#b7dea6' // 100% 处的颜色
                        }]
                    }
                },
                data: [60, 110, 130, 100, 120, 70]
            }
        ]
    };
    var codeList;
    
    var success = function (res) {
        option.xAxis[0].data = res.data.departmentNameList
        option.series[0].data = res.data.sendCountList // 已移送
        option.series[1].data = res.data.doneCountList // 已查结
        // option.series[2].data = res.data.totalCountList // 总案件   
        column1.setOption(option);
        codeList = res.data.departmentCodeList;
    }
    var params = {
        isValid: layui.data('consoleSelect').item
    }
    request.get(Api.countSendDepartment, params, success)

    window.optionReload = function (url) {
        console.log('inner url1', url)
        option.title.text = '2'
        column1.setOption(option);
        // request.get(url, {}, success)
        // request.get(Api.countSendDepartment, {}, success)
    }

    var requestParams = {
        sendDepartment: -2,
    };

    column1.on('click', function (params) {
        // console.log('params',params)
        var url = '';
        requestParams.sendDepartment = codeList[params.dataIndex]
        if (params.seriesIndex == 0) {
            url = Api.getSendListBySendDepartment
        } else if (params.seriesIndex == 1) {
            url = Api.getDoneListBySendDepartment
        }

        layer.open({
            content: '../../../view/excel/excel-list-home.html?type=echarts1&url=' + url + '&requestParams=' + encodeURIComponent(JSON.stringify(requestParams)),
            skin: 'demo-class',
            title: '移送单位案件统计',
            area: ['95%', '95%'],
            type: 2,
            maxmin: true,
            shadeClose: true,
            end: function () {

            }
        });
    });

    window.onresize = function () {
        column1.resize();
    }

})

